package de.bastian.hinterleitner.tools;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;
import de.bastian.hinterleitner.SmallWidget;
import de.bastian.hinterleitner.Widget;
import de.hijacksoft.wyc.R;

public class UpdateWidgetService extends Service {
	
	private static final String TAG = "WatchYourCash_UpdateWidgetService";

	@Override
	public void onStart(Intent intent, int startId) {
		
		Log.d("SERVICE","updating widgets ...");
		
		ComponentName thisWidget = new ComponentName( this, SmallWidget.class );
		RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget_small_layout);
		remoteViews = SmallWidget.configureRemoteViews(this, remoteViews);
		AppWidgetManager.getInstance( this ).updateAppWidget( thisWidget, remoteViews );
		
		thisWidget = new ComponentName( this, Widget.class );
		remoteViews = new RemoteViews(getPackageName(), R.layout.widget_layout);
		remoteViews = Widget.configureRemoteViews(this, remoteViews);
		AppWidgetManager.getInstance( this ).updateAppWidget( thisWidget, remoteViews );
		
		stopSelf();

		super.onStart(intent, startId);
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
}